<template>
    <view class="container">
        <view class="list" v-for="(item, index) in datas.ProductSkuList" :key="index">
            <view class="top flex-between">
                <view class="top_left">
                    <view>{{ item.V_DisplayAttribute }}</view>
                    <view class="number">货号：{{ item.Sku }}</view>
                </view>
                <view class="top_right">
                    <input
                        type="number"
                        v-model="item.Weight"
                        :disabled="look == 1"
                        placeholder="请输入库存"
                        placeholder-class="placeColor" />
                </view>
            </view>
        </view>
        <view class="footer" v-if="look == 0">
            <view class="btn btn-success-hollow" @click="submit">保存</view>
        </view>
    </view>
</template>

<script>
import { mapMutations } from "vuex"
import { InitProductData, SaveProduct } from "@/pages/api/product.js"
export default {
    components: {},
    data() {
        return {
            datas: {},
            id: "",
            look: 0,
        }
    },
    onLoad(e) {
        this.id = e.id
        this.look = e.look
        if (this.look == 1) {
            uni.setNavigationBarTitle({
                title: "重量(KG)",
            })
        }
    },
    mounted() {},
    onShow() {
        this.getinfo()
    },
    methods: {
        ...mapMutations(["UP_ADDPRODUCT_VIEW"]),
        getinfo() {
            let path = "?product_id=" + this.id
            InitProductData(path).then((res) => {
                if (res.State == 1) {
                    this.datas = res.Data.ProductModel
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        submit() {
            let verify = true
            this.datas.ProductSkuList.forEach((e, i) => {
                if (e.Weight === "" || e.Weight < 0) {
                    this.easyToast("请输入正确的重量")
                    return (verify = false)
                }
            })
            if (!verify) {
                return
            }
            let path = "?typeId=0&IsUpdateProductAttribute=0&CheckResult=0"
            SaveProduct(this.datas, path).then((res) => {
                if (res.State == 1) {
                    this.easyToast("保存成功")
                    this.UP_ADDPRODUCT_VIEW(new Date().getTime())
                    setTimeout((e) => {
                        this.easyGoBack()
                    }, 1000)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss">
.container {
    padding: 24rpx 0 130rpx 0;
}
.list {
    padding: 24rpx;
    background: #ffffff;
    margin-bottom: 24rpx;
}
.top {
    font-size: 32rpx;
    color: #333;
    padding: 0 16rpx 16rpx 16rpx;
}
.number {
    font-size: 26rpx;
    color: #999;
}
.top_left {
    display: flex;
    flex-direction: column;

    view {
        padding: 7rpx 0;
    }
}
.body {
    background: #f4f5f6;
    padding: 24rpx;
    margin-bottom: 16rpx;
    & > view {
        display: flex;
        flex-direction: column;
        font-size: 26rpx;
        color: #333333;
    }
    input {
        width: 292rpx;
        height: 68rpx;
        background: #ffffff;
        border-radius: 4rpx;
        font-size: 32rpx;
        text-indent: 20rpx;
        color: $app-color-main;
        font-weight: bold;
    }
    .title {
        padding-bottom: 16rpx;
    }
}
.placeColor {
    font-size: 28rpx;
    color: $color-gray-3;
    font-weight: normal;
}
.btn {
    margin: 16rpx 30rpx 0 30rpx;
}

.top_right {
    input {
        width: 216rpx;
        height: 72rpx;
        background: #f4f5f6;
        border-radius: 36rpx;
        font-size: 32rpx;
        font-weight: bold;
        color: #222a42;
        text-align: center;
    }
}
</style>
